package com.human.server.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import io.minio.MinioClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zooy
 * @since 2025/8/26-15:42
 */
@Configuration
@MapperScan("com.human.server.mapper")
@EnableConfigurationProperties(MinioConfiguration.class)
public class HumanConfiguration {

    /**
     * 添加分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加
        // 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType
        return interceptor;
    }

    @Bean
    public MinioClient minioClient(MinioConfiguration minioConfiguration) {
        return MinioClient.builder()
                .endpoint(minioConfiguration.getEndpoint())
                .credentials(minioConfiguration.getAccessKey(), minioConfiguration.getSecretKey())
                .build();
    }

    @Bean
    public ChatClient dashScopeChatClient(DeepSeekChatModel chatModel) {
        return ChatClient.builder(chatModel).defaultOptions(ChatOptions.builder().build())
                .build();
    }

}
